package com.traffic.api.filter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import com.google.gson.Gson;
import com.traffic.api.jedis.JedisClient;
import com.traffic.api.jedis.running.ApiOrderAcceptExecutor;
import com.traffic.api.util.OrderInfoContext;
import com.traffic.managent.model.system.User;
import com.traffic.managent.service.order.bean.OrderBean;

/**
 * 响应客户 1,本地缓存 2,放入队列 3,响应
 * 
 * @author Guoxing
 *
 */
public class ResponseTOcustomer {
	
	private static Logger logger = Logger.getLogger(ResponseTOcustomer.class);
	
	static JedisClient client = JedisClient.getInstance();

	public static Map<String, Object> doResponse() {
		OrderBean orderBean = OrderInfoContext.getContext();
		Map<String, Object> returnMsg = new HashMap<String, Object>();

		// 1 入缓存
		client.setex("orderno_" + orderBean.getCstmOrderNo() + "accept" , 24 * 60 * 60, orderBean);
		logger.info("ID为"+orderBean.getIds()+",phoneNo为"+orderBean.getPhoneNo()+"的订单入缓存成功!");
		
		// 2,入队列
		ApiOrderAcceptExecutor.service.setOrder(orderBean);// 入队列
		logger.info("ID为"+orderBean.getIds()+",phoneNo为"+orderBean.getPhoneNo()+"的订单入队列成功!");
		
		// 3,返回
		returnMsg.put("status", orderBean.getStatus());
		returnMsg.put("orderNo", orderBean.getOrderNo());
		returnMsg.put("cstmOrderNo", orderBean.getCstmOrderNo());
		returnMsg.put("orderId", orderBean.getIds());
	
		if ("点博".equals(orderBean.getCustomerName())) {
			returnMsg.put("orderTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(orderBean.getOrderTime()));
	
		}
		return returnMsg;
	}

	public static String getHour() {
		String hourStr = new SimpleDateFormat("HH").format(new Date());
		String pattern = "";

		String first = hourStr.substring(0, 1);

		if ("0".equals(first)) {
			pattern = "[0]";
		} else if ("1".equals(first)) {
			pattern = "[01]";
		} else {
			pattern = "[012]";
		}
		pattern += "[0123456789]";
		return pattern;

	}
}
